babl: store pointer to where user data resides instead of copy
authorØyvind Kolås <pippin@gimp.org>
Sun, 14 Jan 2018 22:55:53 +0000 (23:55 +0100)
committerØyvind Kolås <pippin@gimp.org>
Sun, 14 Jan 2018 22:55:56 +0000 (23:55 +0100)
This will make the scenario of changing user data work, we do it
unconditionally to avoid introducing a branch.

babl/babl-fish-path.c
babl/babl-fish.h

index 301dd5c382427bdeff17d8559454a7c73d68d192..d384e1c02abad790b6256a3715f830243f6b2a85 100644 (file)
@@ -675,10 +675,12 @@ _babl_fish_rig_dispatch (Babl *babl)
         if (babl->fish.source == babl->fish.destination)
           {
             babl->fish.dispatch = babl_fish_memcpy_process;
+            babl->fish.data     = (void*)&(babl->fish.data);
           }
         else
           {
             babl->fish.dispatch = babl_fish_reference_process;
+            babl->fish.data     = (void*)&(babl->fish.data);
           }
         break;
 
@@ -688,7 +690,7 @@ _babl_fish_rig_dispatch (Babl *babl)
             /* lift out conversion from single step conversion and make it be the dispatch function
              * itself
              */
-            babl->fish.data = babl->fish_simple.conversion->data;
+            babl->fish.data = &babl->fish_simple.conversion->data;
             babl->fish.dispatch = babl->fish_simple.conversion->dispatch;
           }
         else
@@ -705,11 +707,12 @@ _babl_fish_rig_dispatch (Babl *babl)
           /* do same short-circuit optimization as for simple fishes */
 
           babl->fish.dispatch = conversion->dispatch;
-          babl->fish.data     = conversion->data;
+          babl->fish.data     = &conversion->data;
         }
         else
         {
           babl->fish.dispatch = babl_fish_path_process;
+          babl->fish.data     = (void*)&(babl->fish.data);
         }
         break;
 
@@ -735,7 +738,7 @@ _babl_process (const Babl *cbabl,
   Babl *babl = (void*)cbabl;
   babl->fish.processings++;
   babl->fish.pixels += n;
-  babl->fish.dispatch (babl, source, destination, n, babl->fish.data);
+  babl->fish.dispatch (babl, source, destination, n, *babl->fish.data);
   return n;
 }
 
@@ -771,7 +774,7 @@ babl_process_rows (const Babl *fish,
   babl->fish.pixels += n * rows;
   for (row = 0; row < rows; row++)
     {
-      babl->fish.dispatch (babl, (void*)src, (void*)dst, n, babl->fish.data);
+      babl->fish.dispatch (babl, (void*)src, (void*)dst, n, *babl->fish.data);
 
       src += source_stride;
       dst += dest_stride;
index 36ef0989d705731fd68e18680d27883908dda2ed..a73a358f1b05b1018722cd123ed131cb59b24370 100644 (file)
@@ -32,7 +32,7 @@ typedef struct
   const Babl     *source;
   const Babl     *destination;
   void           (*dispatch) (const Babl *babl, const char *src, char *dst, long n, void *data);
-  void            *data;  /* user data */
+  void          **data;      /* user data - only used for conversion redirect  */
   double          error;    /* the amount of noise introduced by the fish */
 
   /* instrumentation */